<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>application/resources/js/ext/resources/css/ext-all.css"/>
    <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>application/resources/css/sismapc.css" />

    <script type="text/javascript" src="<?php echo base_url(); ?>application/resources/js/ext/adapter/ext/ext-base-debug.js"></script>
    <script type="text/javascript" src="<?php echo base_url(); ?>application/resources/js/ext/ext-all-debug.js"></script>
    
    <!-- Application utilities -->
		<script type="text/javascript" src="<?php echo base_url(); ?>application/resources/js/application/App.js"></script>

    <script type="text/javascript">

    		/**
    		* TODO: these constants and function definitions should be moved to a commom.js file
    		*/
    		
    		// si el usuario final no hace uso de clean URLs debe de agregar '/index.php' a BASE_URL
    		var BASE_URL = '<?php echo base_url(); ?>';
        var BASE_PATH = '<?php echo base_url(); ?>';
    		
    		var USER_CONST = {
		    	/**
		    	 * Permissions constants
		    	 */
					PERM_ADMINISTER_USERS: '<?php echo PERM_ADMINISTER_USERS;?>',
					PERM_ADMINISTER_DOCUMENTS: '<?php echo PERM_ADMINISTER_DOCUMENTS;?>',
					PERM_ACCESS_DOCUMENTS: '<?php echo PERM_ACCESS_DOCUMENTS;?>',
					PERM_ACCESS_DOWNLOAD_DOCUMENTS: '<?php echo PERM_ACCESS_DOWNLOAD_DOCUMENTS;?>',

					/**
					 * Roles Ids
					 */
					ROLE_ADMINISTRATOR: '<?php echo ROLE_ADMINISTRATOR;?>',
					ROLE_ANONYMOUS_USER: '<?php echo ROLE_ANONYMOUS_USER;?>',
					ROLE_AUTHENTICATED_USER: '<?php echo ROLE_AUTHENTICATED_USER;?>' 				
				};
				
    		/**
		     * Determine whether the user has a given privilege.
				 *
		     * @return Boolean TRUE if the current user has the requested permission.
		     */
		    function access(string) {
		    	if( myApp.userdata != undefined ) {
		    		for( var i = 0; i < myApp.userdata.permissions.length; i++ ) {
		    			if( myApp.userdata.permissions[i] == string ) {
		    				return true;
		    			}
		    		}
		    	}
		    	return false;
		    }

		    function isUserLoggedIn() {
			  	if( myApp.userdata != undefined ) {
						return myApp.userdata.logged_in;
				  }  
				  return false;
		    }

		    function doLogin() {
		        Ext.Ajax.request({
		            url: BASE_URL + 'users/logout',
		            method: 'POST',
		            success: function(xhr) {
		                window.location = BASE_URL + 'users/login';
		            }
		        });
		    }

		    function doLogout() {
		        Ext.Ajax.request({
		            url: BASE_URL + 'users/logout',
		            method: 'POST',
		            success: function(xhr) {
		                window.location = BASE_URL;
		            }
		        });
		    }

		    var myApp = new Ext.App({
		    	showConfirmDialogOnRemoveRecord: true,

		    	FILTER_TYPES: {
		    		LOCAL: true,
		    		REMOTE: false
		    	},
		    	
		    	filterType: false, //this.FILTER_TYPES.REMOTE
		    	gridSelectedIndex: -1, // no row selected

		    	sessionId: '<?php echo $this->session->userdata('session_id');?>',
		    	userdata: Ext.util.JSON.decode('<?php echo $userdata;?>')
		    });

        Ext.onReady(function() {
            Ext.QuickTips.init();
            Ext.BLANK_IMAGE_URL = BASE_PATH + 'application/resources/js/ext/resources/images/default/s.gif';
            Ext.form.Field.prototype.msgTarget = 'under';
        });
    </script>

    <title><?php echo $title; ?></title>
</head>
<body>